package Demo;

import java.awt.desktop.QuitHandler;
import java.util.Scanner;

public class Demo8 {
    private static Object locker = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            synchronized(locker){
                System.out.println("t1wait before");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t1wait after");
            }
        });
        Thread t2 = new Thread(()->{
            System.out.println("t2wait before");
            Scanner scanner = new Scanner(System.in);
            scanner.next();
            synchronized (locker){
                locker.notify();
            }
            System.out.println("t2wait after");
        });
        t1.start();
        t2.start();
    }
}
